set

abstract fun set(index: Long, @Nullable element: Any): Boolean

Inserts the specified element into the array at the specified index.

If there is an existing element at the specified index, it will be replaced. If the index exceeds the array size, the array will be extended and the elements between the last inserted item and the index will be set to undefined.

The type mapping rules are the following:


| Java               | JavaScript                    |
|--------------------|-------------------------------|
| Double             | Number                        |
| String             | String                        |
| Boolean            | Boolean                       |
| null               | null                          |
| JsObject           | Object                        |
| Node               | Node                          |
| List<?>            | Array or Proxy Object         |
| Set<?>             | Set or Proxy Object           |
| Map<?,?>           | Map or Proxy Object           |
| byte[]             | ArrayBuffer                   |
| Object             | Proxy Object                  |

If you pass a non-primitive Java object to JavaScript, it will be converted into a "proxy" JavaScript object. Method and property calls to this object will be delegated to the Java object. For security reasons, JavaScript can access only those methods and fields of the injected Java object that are explicitly marked as accessible either using the JsAccessible annotation or via the JsAccessibleTypes class.

Java collections that are not made accessible to JavaScript using the JsAccessible annotation or via the JsAccessibleTypes class are converted to JavaScript collections. The content of the converted collection is a deep copy of the Java collection. Modifications of the converted collection in JavaScript do not affect the collection in Java.

Java collections that are made accessible to JavaScript using the JsAccessible annotation or via the JsAccessibleTypes class are wrapped into a JavaScript proxy object. Such proxy objects can be used to modify the collection in Java.

Return

true if the element is successfully inserted, false otherwise

Parameters

index

the index in the array to insert the element. Cannot be negative or exceed the maximum array size (232-1)

element

the element to insert

Throws

when element is a JsObject from a different web page or a frame

when the JavaScript object is already disposed or invalid